package com.jixi.service.impl;

import cn.dev33.satoken.stp.StpUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jixi.mapper.ClassesMapper;
import com.jixi.pojo.entity.Classes;
import com.jixi.pojo.vo.ClassDetailVo;
import com.jixi.service.ClassesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Locale;

@Service
public class ClassesServiceImpl extends ServiceImpl<ClassesMapper, Classes> implements ClassesService {
    @Autowired
    private ClassesMapper classesMapper;
    /**
     * 查询管理班级详情
     *
     * */
    @Override
    public List<ClassDetailVo> getClassOrderDetail() {
        //获取当前班主任id
        Long teacherId = StpUtil.getLoginIdAsLong();
        //获取今日日期
        // 创建一个Date对象（当前日期和时间）
        java.util.Date date = new Date();
        // 创建一个SimpleDateFormat对象，指定日期格式
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault());
        // 使用SimpleDateFormat的format方法将Date对象转换为String
        String formattedDate = sdf.format(date);
        //根据班主任id查询
        List<ClassDetailVo> list = classesMapper.getClassOrderDetail(teacherId,formattedDate);
        return list;
    }
    /**
     * 查询管理班级个数
     *
     * */
    @Override
    public Long getTotalClasses() {
        //获取当前班主任id
        Long teacherId = StpUtil.getLoginIdAsLong();
        //根据班主任id查询
        LambdaQueryWrapper<Classes> queryWrapper1 = new LambdaQueryWrapper<>();
        queryWrapper1.eq(Classes::getTeacherId, teacherId).eq(Classes::getStatus,1);
        Long totalClasses = classesMapper.selectCount(queryWrapper1);
        return totalClasses;
    }
}
